package com.zhangqi.zhxa.base;

import android.app.Activity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.TextView;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.zhangqi.zhxa.MainActivity;
import com.zhangqi.zhxa.R;

/**
 * 五个标签页的基类
 * @author Zhang Qi
 * @date 2016-4-28
 *
 */
public abstract class BasePager {

    public Activity mActivity;

    public View mRootView;//总的布局view,用base_pager.xml填充
    public TextView tvTitle;//基础页标题栏标题
    public ImageButton btnMenu;//基页左上角菜单按钮

    //帧布局容器，奖来要动态的向里面添加内容
    public FrameLayout flContent;//base_pager.xml中的主界面

    public BasePager(Activity activity){
        mActivity = activity;
        initView();
    }

    /**
     * 初始化布局
     */
    public void initView(){
        mRootView = View.inflate(mActivity, R.layout.base_pager, null);
        tvTitle = (TextView) mRootView.findViewById(R.id.tv_title1);//基页标题栏标题
        btnMenu = (ImageButton) mRootView.findViewById(R.id.btn_menu);//基页左上角菜单按钮
        flContent = (FrameLayout) mRootView.findViewById(R.id.fl_content);//base_pager.xml中的主界面

        btnMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toggle();//点击隐藏侧边栏
            }
        });

    }


    /**
     * 侧边栏展开或者收起的方法
     */
    private void toggle(){
        MainActivity mainUI = (MainActivity) mActivity;
        SlidingMenu slidingMenu = mainUI.getSlidingMenu();
        slidingMenu.toggle();//开关（如果开了，它就显示是关，如果关，它就开）
    }

    /**
     * 初始化数据
     */
    public abstract void initData();

}
